1 00:00:00,990 --> 00:00:05,760 Alrighty, in this lecture we're going to be implementing animations for our zombies. 2 00:00:05,760 --> 00:00:10,560 We're going to need an animation for when our zombies are walking around, when they're standing still 3 00:00:10,560 --> 00:00:12,390 in an idle state when they're running. 4 00:00:12,390 --> 00:00:16,650 And we'll also need some animations for when our zombies try to attack a player. 5 00:00:17,200 --> 00:00:21,700 Now, I'm not the best at creating animations, but I did create animations for my zombies. 6 00:00:21,700 --> 00:00:23,800 So let me open up my animation editor. 7 00:00:23,920 --> 00:00:26,230 And as you can see, I've created several animations. 8 00:00:26,230 --> 00:00:28,540 One for when my zombie is walking. 9 00:00:28,540 --> 00:00:31,540 I created an animation for when my zombie is running. 10 00:00:32,630 --> 00:00:38,810 I've created an animation for an idle state for my zombie, as well as a second idle state. 11 00:00:38,960 --> 00:00:43,700 And then I've created some attack animations when the zombie is swinging at a player. 12 00:00:44,270 --> 00:00:49,190 I encourage you to create your own animations as well, but if you would like to use my animations or 13 00:00:49,190 --> 00:00:53,870 make some adjustments and modifications to my animations, then I will have this rig attached to the 14 00:00:53,870 --> 00:00:57,110 lecture for you to upload the animations to your Roblox account. 15 00:00:58,200 --> 00:01:04,290 Now, the easiest way for us to implement these animations into our zombie would be to copy the script 16 00:01:04,290 --> 00:01:07,560 Roblox already uses for animating character models. 17 00:01:07,560 --> 00:01:12,360 We can grab this script by generating a new AR 15 rig, so we'll go to Rig Builder. 18 00:01:12,360 --> 00:01:18,210 We'll make a new block rig avatar, and inside of this rig we're going to find an animate script. 19 00:01:18,210 --> 00:01:22,920 So what we can go ahead and do is open up this local script and copy all of the code inside of it, 20 00:01:22,920 --> 00:01:25,350 and place it inside of a server script. 21 00:01:25,350 --> 00:01:30,600 So what I'm going to do is I'm going to grab one of my zombies from server storage. 22 00:01:31,140 --> 00:01:36,180 I'll grab my regular zombie and place them inside of the workspace, and then we can go ahead and create 23 00:01:36,180 --> 00:01:38,130 a new server script inside of him. 24 00:01:38,130 --> 00:01:43,140 I'm going to call it the animate script, and they're just going to paste all of that code inside of 25 00:01:43,140 --> 00:01:43,680 there. 26 00:01:43,920 --> 00:01:48,570 And then we're also going to go ahead and copy all of the descendants of that local script. 27 00:01:48,570 --> 00:01:54,660 So we're going to go in here, copy that, and then paste it inside of our animate script as well. 28 00:01:54,750 --> 00:02:01,020 And to make this script work on the server, there's a small section that we're going to need to remove. 29 00:02:01,020 --> 00:02:03,330 That's for some client sided stuff. 30 00:02:03,450 --> 00:02:07,290 So yeah, it's right here at line 757. 31 00:02:07,290 --> 00:02:12,420 It's attempting to grab the local player and listen to the chatted event, but since this is inside 32 00:02:12,420 --> 00:02:17,760 of a server script, there is no local player, so we can just go ahead and delete that section. 33 00:02:17,760 --> 00:02:22,620 And now this code should work on our zombie, but for the server. 34 00:02:23,770 --> 00:02:28,840 Then what we can go ahead and do is we can grab all of the animation IDs that we've uploaded and paste 35 00:02:28,840 --> 00:02:31,270 them into their respective animation instances. 36 00:02:31,270 --> 00:02:36,280 So for example, with our Idalene animations, we can take the first one and paste its id into this 37 00:02:36,280 --> 00:02:37,480 animation id property. 38 00:02:37,480 --> 00:02:39,880 And then we can do the same for the second idalene animation. 39 00:02:39,880 --> 00:02:44,260 And then for the running animation, we can paste it into this animation instance. 40 00:02:44,260 --> 00:02:49,420 And for the walking animation we can paste it inside of this walk animation instance. 41 00:02:50,300 --> 00:02:56,210 So I've gone ahead and pasted in my animations for each one of these animation instances, and then 42 00:02:56,210 --> 00:03:02,390 to implement the attack animations, we can go ahead and go back to the zombie AI server script for 43 00:03:02,390 --> 00:03:03,140 our zombies. 44 00:03:03,140 --> 00:03:10,310 And inside of here is where we could play an attack animation when the zombie has this attack function 45 00:03:10,310 --> 00:03:11,000 called. 46 00:03:11,540 --> 00:03:16,970 So that means we're going to have to go into the properties module script for our zombies and insert 47 00:03:16,970 --> 00:03:22,040 those two attack animations that we've uploaded, and place them inside of our attack animation IDs 48 00:03:22,040 --> 00:03:22,760 table. 49 00:03:23,920 --> 00:03:29,770 So I've gone ahead and pasted in my attack animation IDs inside my attack animation IDs table, and 50 00:03:29,770 --> 00:03:35,260 now we can head back to our zombie AI server script, and we're going to go ahead and make a reference 51 00:03:35,260 --> 00:03:38,770 to the animator instance that is inside of the humanoid of our zombie. 52 00:03:38,770 --> 00:03:44,110 So we'll create a new variable, we'll call it the animator, and it's going to be equal to my humanoid 53 00:03:44,110 --> 00:03:44,620 dot. 54 00:03:44,620 --> 00:03:46,540 And we're going to get the animator. 55 00:03:46,960 --> 00:03:51,310 Then what we can go ahead and do is inside of our attack function. 56 00:03:51,310 --> 00:03:56,830 When we're attacking a player, we can go ahead and create and play a random attack animation. 57 00:03:56,830 --> 00:03:59,890 So I'm going to create a new attack animation instance here. 58 00:03:59,890 --> 00:04:01,540 So I'll just call it attack Anim. 59 00:04:01,540 --> 00:04:03,700 And that's equal to instance dot new. 60 00:04:03,700 --> 00:04:05,560 Create a new animation. 61 00:04:06,200 --> 00:04:12,200 Now we can go ahead and set the animation ID equal to one of the random IDs inside of our attack animation 62 00:04:12,200 --> 00:04:17,150 IDs table, so that'll be equal to properties dot attack animation IDs. 63 00:04:17,600 --> 00:04:19,790 And then we're going to use RNG to pick a random one. 64 00:04:19,790 --> 00:04:24,740 So next integer one to the number of elements inside of that table. 65 00:04:25,310 --> 00:04:31,370 And then once we get that animation, we can go ahead and get the track by loading it. 66 00:04:31,370 --> 00:04:36,200 So we'll refer to our animator and load the animation and pass our track animation. 67 00:04:36,380 --> 00:04:39,770 And then we can go ahead and play that track. 68 00:04:40,100 --> 00:04:45,980 And then when that track has ended, we'll connect a function to that event and we'll go ahead and clean 69 00:04:45,980 --> 00:04:47,660 up our attack animation instance. 70 00:04:47,660 --> 00:04:48,830 So we'll destroy that. 71 00:04:48,830 --> 00:04:52,610 And then we'll also destroy the attack animation track. 72 00:04:53,900 --> 00:04:58,520 So now we should have all the animations implemented for our zombies. 73 00:04:58,520 --> 00:05:04,910 What we can go ahead and do is copy this new service script that we've just updated, and paste that 74 00:05:04,910 --> 00:05:11,090 inside of each one of the zombies in our game, and delete the old zombie AI script. 75 00:05:12,470 --> 00:05:18,800 And then we can also go ahead and grab our animate script and copy that, and then also put it inside 76 00:05:18,800 --> 00:05:21,950 of each one of our zombie instances. 77 00:05:22,610 --> 00:05:27,860 So we'll just go in through here and we'll paste that script inside of each one of our zombies. 78 00:05:27,860 --> 00:05:32,900 And now every single zombie in our game should be animated, and they should play an attack animation 79 00:05:32,900 --> 00:05:34,940 when they are trying to attack a player. 80 00:05:35,420 --> 00:05:42,380 So let's go ahead and let's grab each one of these zombies and place them inside of the workspace in 81 00:05:42,380 --> 00:05:43,490 the zombies folder. 82 00:05:43,640 --> 00:05:46,070 So here's all of the zombies in our game. 83 00:05:46,100 --> 00:05:49,130 I'm going to go ahead and clean up these two guys. 84 00:05:49,130 --> 00:05:52,550 So I'm going to get rid of this guy and set this guy aside. 85 00:05:53,930 --> 00:06:00,080 And now let's go ahead and run our game to see if they have the different animations, um, playing 86 00:06:00,080 --> 00:06:01,610 on the zombies. 87 00:06:01,610 --> 00:06:03,320 So if we run our game. 88 00:06:04,420 --> 00:06:09,460 As you can see now, each one of our zombies are animated, so when they walk around they play their 89 00:06:09,460 --> 00:06:10,780 walking animation. 90 00:06:10,870 --> 00:06:15,730 Or if they're running fast enough, like this guy is, then they're playing the running animation. 91 00:06:16,530 --> 00:06:20,700 Uh, and so far everything looks fine with how these guys are animated. 92 00:06:20,730 --> 00:06:25,890 So now what we need to do is spawn a player into the game and see if they play their attack animations 93 00:06:25,890 --> 00:06:27,570 when they try to attack us. 94 00:06:28,430 --> 00:06:30,830 So let's go ahead and playtest our game. 95 00:06:33,330 --> 00:06:36,300 Let's have one of these guys run after us. 96 00:06:37,130 --> 00:06:40,790 So here comes all the zombies. 97 00:06:41,650 --> 00:06:44,380 And let's go ahead and see if they play the attack animation. 98 00:06:44,380 --> 00:06:45,940 So there you go. 99 00:06:45,940 --> 00:06:50,050 As you can see, they're playing the attack animation and they're dealing damage to me. 100 00:06:52,510 --> 00:06:57,040 So just like that, we've easily added animations to our zombies. 101 00:06:57,040 --> 00:06:59,410 I'll see you in the next lecture.